﻿<ResourceDictionary 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >

  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="Shared.xaml" />
  </ResourceDictionary.MergedDictionaries>

  <Style x:Key="{x:Type TreeView}" TargetType="TreeView">
    <Setter Property="OverridesDefaultStyle" Value="True" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="TreeView">
          <Border 
            Name="Border" 
            CornerRadius="1" 
            Background="{TemplateBinding Background}"
            BorderBrush="{TemplateBinding BorderBrush}"
            BorderThickness="{TemplateBinding BorderThickness}" >
            <ScrollViewer 
              Focusable="False"
              CanContentScroll="False"
              Padding="0">
              <ItemsPresenter/>
            </ScrollViewer>
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
			<Setter Property="Focusable" Value="False"/>
			<Setter Property="Width" Value="10"/>
			<Setter Property="Height" Value="16"/>
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="{x:Type ToggleButton}">
						<Border Width="12" Height="16" Background="Transparent" Padding="0,5,0,5">
							<Path Fill="#FF595959" Stroke="#FF989898" x:Name="ExpandPath" Data="M0,0 L0,6 L6,0 z">
								<Path.RenderTransform>
									<RotateTransform Angle="135" CenterX="3" CenterY="3"/>
								</Path.RenderTransform>
							</Path>
						</Border>
						<ControlTemplate.Triggers>
							<Trigger Property="IsMouseOver" Value="True">
								<Setter Property="Stroke" TargetName="ExpandPath" Value="#FF1BBBFA"/>
								<Setter Property="Fill" TargetName="ExpandPath" Value="#FF595959"/>
							</Trigger>
							<Trigger Property="IsChecked" Value="True">
								<Setter Property="RenderTransform" TargetName="ExpandPath">
									<Setter.Value>
										<RotateTransform Angle="180" CenterX="3" CenterY="3"/>
									</Setter.Value>
								</Setter>
								<Setter Property="Fill" TargetName="ExpandPath" Value="Transparent"/>
								<Setter Property="Stroke" TargetName="ExpandPath" Value="#FF262626"/>
							</Trigger>
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>

		<Style TargetType="{x:Type TreeViewItem}">
			<Setter Property="Background" Value="Transparent"/>
			<Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
			<Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
			<Setter Property="Padding" Value="1,0,0,0"/>
			<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>

			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="{x:Type TreeViewItem}">
						<Grid>
							<Grid.ColumnDefinitions>
								<ColumnDefinition MinWidth="12" Width="Auto"/>
								<ColumnDefinition Width="Auto"/>
								<ColumnDefinition Width="*"/>
							</Grid.ColumnDefinitions>
							<Grid.RowDefinitions>
								<RowDefinition Height="Auto"/>
								<RowDefinition/>
							</Grid.RowDefinitions>
							<ToggleButton x:Name="Expander" Style="{StaticResource ExpandCollapseToggleStyle}" ClickMode="Press" IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"/>
							<Border SnapsToDevicePixels="true" x:Name="Bd" Grid.Column="1" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
								<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" x:Name="PART_Header" ContentSource="Header"/>
							</Border>
							<ItemsPresenter x:Name="ItemsHost" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1"/>
						</Grid>
						<ControlTemplate.Triggers>
						  <Trigger Property="HasItems"
                   Value="false">
                <Setter TargetName="Expander"
                    Property="Visibility"
                    Value="Hidden"/>
              </Trigger>
							<Trigger Property="IsExpanded" Value="false">
								<Setter TargetName="ItemsHost" Property="Visibility" Value="Collapsed"/>
							</Trigger>
							<!--DataTrigger Binding="{Binding RelativeSource={RelativeSource Self},Path=Key.SubKeyCount}" Value="0">
								<Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
							</DataTrigger-->
							<Trigger Property="IsSelected" Value="true">
								<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
								<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
							</Trigger>
							<MultiTrigger>
								<MultiTrigger.Conditions>
									<Condition Property="IsSelected" Value="true"/>
									<Condition Property="IsSelectionActive" Value="false"/>
								</MultiTrigger.Conditions>
								<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
								<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
							</MultiTrigger>
							<Trigger Property="IsEnabled" Value="false">
								<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
							</Trigger>
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>

</ResourceDictionary>